<?php
      require_once("mp3.php");
      require_once("usuario.php");
      session_start();
      
     if (!empty($_POST['substr']))
        {
        $substr = $_POST['substr'];
        $user = Usuario::findByUsername($_SESSION['username']);
        $id = $user->get_id();
        $array = Mp3::findbytitolplus($substr, $id);
        if (count($array) > 0)
        {
            $array_json = Array();
            $index = 0;

            foreach ($array as $s)
            {
                $array_json[]['nom'] = $s->get_titol();
                $array_json[$index]['id'] = $s->get_id();
                $index++;
            }
            $string = json_encode($array_json);
            echo $string;
        }
        else
        {
            $string = json_encode("ko");
            echo $string;
        }

        //$sm->assign('playlist',$array_noms);
    }
    else if ($_POST['substr'] == "")
    {
        $string = json_encode("ko");
            echo $string;
    }
?>
